//
//  ViewController.m
//  progress
//
//  Created by 陶宏路 on 16/7/5.
//  Copyright © 2016年 陶路路. All rights reserved.
//

#import "ViewController.h"
@interface ViewController ()

@property (nonatomic,weak) UILabel * lable;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    
    [manager GET:@"http://127.0.0.1/images/head1.png" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        NSLog(@"我爱你");
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"我爱你");
        
        NSLog(@"%@",responseObject);

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    
        
    }];
    
    [self masonry];
 }


-(void)masonry{
    
    UIImageView * imageview = [[UIImageView alloc]init];
    imageview.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:imageview];
    [imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).offset(100);
        make.left.equalTo(self.view).offset(140);
        make.right.equalTo(self.view).offset(-140);
        make.height.equalTo(make.width);
        
    }];
    
    [imageview sd_setImageWithURL:[NSURL URLWithString:@"http://127.0.0.1/images/head1.png"]];
    
    UILabel * lable = [[UILabel alloc]init];
    self.lable = lable;
    
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
    }];
    
}


- (void)demo {
    
    NSURL *url = [NSURL URLWithString:@""];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
       
        if (connectionError) {
            
            NSLog(@"conn error");
        }
        
        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
        
        if (httpResponse.statusCode == 200 && httpResponse.statusCode == 304) {
            
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
            
            NSLog(@"%@",dict);
        } else {
            
            NSLog(@"error");
        }
        
        
    }];
    
}
@end
